import http from './http';
import type { MaterialClass, MaterialProperty } from '../types/menu';

/** 获取物料分类列表 */
export async function getMaterialClass(): Promise<MaterialClass[]> {
  // 直接返回后端数组
  const resp = await http.get<MaterialClass[]>('/api/menu/materialClass');
  // 如果后端使用 envelope，可以适配此处；现在假设 http 拦截器已返回 resp.data
  return resp as unknown as MaterialClass[];
}

/** 获取指定物料分类的属性及选项 */
export async function getPropertiesWithItemsByClassId(classId: number): Promise<MaterialProperty[]> {
  const resp = await http.get<MaterialProperty[]>(`/api/menu/propertiesWithItemsByClassId?classId=${classId}`);
  return resp as unknown as MaterialProperty[];
}

/** 获取 BOM 条目产品下拉（一级）: List<String> */
export async function getBomProducts(): Promise<string[]> {
  const resp = await http.get<string[]>('/api/menu/bom/products');
  return resp as unknown as string[];
}

/** 获取某产品类型下的 BOM 条目二级分类下拉：List<String> */
export async function getBomProductClasses(productType: string | number): Promise<string[]> {
  const resp = await http.get<string[]>(`/api/menu/bom/products/class?productType=${productType}`);
  return resp as unknown as string[];
}

/** 获取 SKU 产品（产品明细页子菜单选项）：List<String> */
export async function getSkuProducts(): Promise<string[]> {
  const resp = await http.get<string[]>('/api/menu/sku/products');
  return resp as unknown as string[];
}
export default {
  getMaterialClass,
  getPropertiesWithItemsByClassId,
  getBomProducts,
  getBomProductClasses,
  getSkuProducts,
};
